package com.mdd.admin.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mdd.admin.service.ISettingSmsService;
import com.mdd.admin.service.ISettingWebHookService;
import com.mdd.common.entity.system.SystemConfig;
import com.mdd.common.mapper.system.AdminSystemConfigMapper;
import com.mdd.common.util.*;
import com.qcloud.cos.model.ciModel.auditing.Conf;
import jdk.nashorn.internal.runtime.regexp.joni.Config;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * webhook服务实现类
 */
@Service
public class SettingWebHookServiceImpl implements ISettingWebHookService {

    /**
     * webhook列表
     *
     * @author fzr
     * @return List<Map<String, Object>>
     */
    @Override
    public List<SystemConfig> list() {
        List<SystemConfig> webhook = ConfigUtils.getListByType("webhook");
        return webhook;
    }

    /**
     * webhook详情
     *
     * @author fzr
     * @param alias 别名
     * @return Map<String, Object>
     */
    @Override
    public SystemConfig detail(String alias) {
        AdminSystemConfigMapper model = SpringUtils.getBean(AdminSystemConfigMapper.class);

        SystemConfig config = model.selectOne(
                new QueryWrapper<SystemConfig>()
                        .select("id", "type", "name", "value")
                        .eq("type", "webhook")
                        .eq("name", alias));
        return config;
    }

    /**
     * webhook保存
     *
     * @author fzr
     * @param params 参数
     */
    @Override
    public void save(Map<String, String> params) {
        ConfigUtils.set("webhook", params.get("alias"), params.get("value"));
    }

    @Override
    public void delete(Map<String, String> params) {
       ConfigUtils.delete("webhook",params.get("alias"));
    }

}
